package com.itheima.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.domain.Setmeal;
import com.itheima.domain.vo.SetmealVo;
import com.itheima.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;



    @PostMapping
    public R<String> save(@RequestBody SetmealVo setmealVo) {
        log.info("新增套餐信息：{}", setmealVo.toString());
        return setmealService.adminSetmealSave(setmealVo);
    }


    @GetMapping("/page")
    public R<Page<Setmeal>> pageselect(@RequestParam(value = "name",required = false)String name, @RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        log.info("page={},pageSize={},name={}", page, pageSize, name);
       return setmealService.adminSetmealPageselect(name, page, pageSize);

    }

    @PutMapping
    public R<String> updateDish(@RequestBody SetmealVo setmealVo){
        log.info("修改套餐信息：{}", setmealVo.toString());
        return setmealService.adminSetmealUpdate(setmealVo);

    }

    @GetMapping("/{id}")
    public R<SetmealVo> selectById(@PathVariable String id){
       log.info("通过id查询id={}", id);
       return setmealService.adminSetmealSelectById(id) ;
    }

    @PostMapping("/status/{status}")
    public R<String> dishStatus(@RequestParam("ids") List<String> ids,@PathVariable Integer status){
       log.info("启用或禁用套餐信息id集合ids={}",ids);
       return setmealService.adminSetmealUpdateStatus(ids, status);


    }

    @DeleteMapping
    public R<String> dishDelete(@RequestParam("ids") List<String> ids){
        log.info("删除套餐信息：{}",ids);
        return setmealService.adminSetmealDelete(ids);
    }



}
